#include "RingBuffer.hpp"
#include <pthread.h>
#include <unistd.h>
#include <ctime>
#include <functional>

using namespace RingBufferModule;
void test()
{
    std::cout << "hahahah  test...." << std::endl;
}
void *Consumer(void *args)
{
    RingBuffer<int>* ring_buffer = static_cast<RingBuffer<int> *>(args); // 让不同线程看到同一份阻塞队列

    while (true)
    {
        //sleep(1);
        int data;
        ring_buffer->Pop(&data);
        std::cout << "消费了一个数据：" << data << std::endl;
    }
}

void *Productor(void *args)
{
    RingBuffer<int> *ring_buffer = static_cast<RingBuffer<int> *>(args); // 让不同线程看到同一份阻塞队列
    int data = 0;
    while (true)
    {
        sleep(1);
        ring_buffer->Equeue(data);
        std::cout << "生产了一个数据：" << data << std::endl;
        data++;
    }
}
int main()
{
    RingBuffer<int> *ring_buffer = new RingBuffer<int>(5);
    pthread_t c, p;
    pthread_create(&c, nullptr, Consumer, ring_buffer);
    pthread_create(&p, nullptr, Productor, ring_buffer);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    delete ring_buffer;
    return 0;
}